import request from '@/utils/request';
import { download } from '@/utils/request';
import { AxiosPromise } from 'axios';
import { BizOrderVo } from '@/api/operation/order/types';
import { UnwrapRef } from 'vue';

/**
 * 查询列表
 * @param query
 * @returns {*}
 */

export const listOrder = (query?: PageQuery): AxiosPromise<BizOrderVo[]> => {
  return request({
    url: '/biz-vendor/order/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询详细
 * @param id
 */
export const getOrder = (id: string | number): AxiosPromise<BizOrderVo> => {
  return request({
    url: '/biz-vendor/order/' + id,
    method: 'get'
  });
};

/**
 * 新增
 * @param data
 */
export const addOrder = (data: BizOrderVo) => {
  return request({
    url: '/biz-vendor/order',
    method: 'post',
    data: data
  });
};

/**
 * 修改
 * @param data
 */
export const updateOrder = (data: BizOrderVo) => {
  return request({
    url: '/biz-vendor/order',
    method: 'put',
    data: data
  });
};

/**
 * 删除
 * @param id
 */
export const delOrder = (id: string | number | Array<string | number>) => {
  return request({
    url: '/biz-vendor/order/' + id,
    method: 'delete'
  });
};

/**
 * 导出
 * @param query
 * @returns
 */
export const exportOrder = (query?: PageQuery) => {
  let fileName=query.timeRangeStart+"-"+query.timeRangeEnd+"订单列表.xlsx";
   download('/biz-vendor/order/export',query,fileName);
};

/**
 * 导出
 * @param query
 * @returns
 */
// export const exportOrder = (query?: PageQuery): AxiosPromise<BizOrderVo[]> => {
//   return download({
//     url: '/biz-vendor/order/export',
//     method: 'post',
//     params: query,
//     responseType: 'arraybuffer'
//   });
// };

/**
 * 发起退款
 * @param data
 */
export const setRefund = (
  data: UnwrapRef<{
    totalOrderActualPayment: string;
    orderId: string;
    refundReason: string;
    currentRefundAmount: string;
    refundAmount: string;
  }>
) => {
  data.refundAmount = data.currentRefundAmount;
  return request({
    url: '/biz-vendor/refund',
    method: 'post',
    data: data
  });
};
